package first;

/**
 * @author ecko
 * 
 */
public class QuickSort {
	static void quicksort(int[] arr, int l, int r) {
		int x = arr[(l + r) / 2];
		int i = l, j = r;
		do {
			while (arr[i] < x)
				++i;
			while (arr[j] > x)
				--j;
			if (i <= j) {
				int temp = arr[i];
				arr[i] = arr[j];
				arr[j] = temp;
				i++;
				j--;
			}
		} while (i <= j);
		if (l < j)
			quicksort(arr, l, j);
		if (i < r)
			quicksort(arr, i, r);
	}

	public static void sort(int[] arr) {
		int start = 0, end = arr.length - 1;
		quicksort(arr, start, end);
	}
}
